package datalayer;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import javax.swing.JOptionPane;

import Model.Nummer;

public class DBOpath {
	
	private String url = "jdbc:sqlite:./database.sqlite";

	protected static Connection conn;
	
	
	public DBOpath() {
		try {
			Class.forName("org.sqlite.JDBC").newInstance();
			conn = (Connection) DriverManager.getConnection(url);
			System.err.println("connected to database");

		} catch (Exception e) {
			System.out.println(e.getMessage());
			JOptionPane.showMessageDialog(null,"Kan geen verbinding met Database maken!");
		}
	}
	
	public void save(String path){
		try {
			
			Statement stmt = conn.createStatement();
			
			String sql = "INSERT INTO Path(path) VALUES ('" +
					path +
					"')";
			
//			stmt.executeUpdate(sql);

		} catch (SQLException e) {
			e.printStackTrace();
		}	
	}
	
	public String load(){
		Statement stmt;
		String path = " ";
		
		try {
			
			stmt = conn.createStatement();
			String sql = "Select path from Path";

			ResultSet rsltst = stmt.executeQuery(sql);
		
			path = rsltst.getString(1);
					
			conn.close();
			
			return path;
		} catch (SQLException e) {
			return null;
		}			
	}

}
